package hottargui.config;

import hottargui.framework.*;


public class AlphaEndTurnState implements TarguiState {

	Game gameContext;
	
	public AlphaEndTurnState(Game game)
	{
		this.gameContext = game;
	}
	
	@Override
	public boolean buy(int count, Position deploy) throws IllegalActionException {
		throw new IllegalActionException(this.getState());
	}

	@Override
	public State getState() {
		return State.endTurn;
	}

	@Override
	public boolean move(Position from, Position to, int count)
			throws IllegalActionException {
		throw new IllegalActionException(this.getState());
	}

	@Override
	public void newGame() throws IllegalActionException {
		throw new IllegalActionException(this.getState());
	}

	@Override
	public void rollDie() throws IllegalActionException {
		throw new IllegalActionException(this.getState());
	}

	@Override
	public PlayerColor turnCard() throws IllegalActionException {
		// TODO: Replace this stub
		// TODO: Implement turncontrol
		GameObjectServer gos = gameContext.getGameObjectServer();
		TurnSequenceStrategy turnSequence = gos.getTurnSequenceStrategy();
		PlayerColor nextPlayerColor = turnSequence.getNextPlayerColor(); 
		
		//Check if the color is None, we do not have at None player
		if(nextPlayerColor.equals(PlayerColor.None))
			gameContext.setState(gameContext.getFactory().getEndRoundState(gameContext));		
		else			
		{
			gos.getGameData().setCurrentPlayer(nextPlayerColor);
			gameContext.setState(gameContext.getFactory().getMoveState(gameContext));	
		}
		return gameContext.getPlayerInTurn().getColor();
	}

	@Override
	public PlayerColor getWinner() throws IllegalActionException {
		throw new IllegalActionException(this.getState());
	}

}
